import cn.edu.Factor.method.patton.Factor;
import javax.xml.parsers.*;

import cn.edu.Factor.method.patton.Vehicle;
import org.w3c.dom.*;
import java.io.*;


public class Main {
    public static void main(String[] args){

        try{
            Factor factor;

            Class classReflection = Class.forName(ReadClassNameFromXML());
            Object objectReflection = classReflection.newInstance();

            factor = (Factor) objectReflection;
            Vehicle vehicle = factor.vehicleFactoryMethod();
            System.out.println(vehicle.showVehicleName());
        }catch (Exception ex){
            System.out.println(ex.getMessage());
        }

    }

    public static String ReadClassNameFromXML(){

        String className = "";
        try{
            //读取XML文件
            DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = dFactory.newDocumentBuilder();
            Document doc;
            doc = builder.parse(new File("src//config.xml"));

            //获取包含类名的文本结点
            NodeList nl = doc.getElementsByTagName("className");
            Node classNode=nl.item(0).getFirstChild();
            className=classNode.getNodeValue();


        }catch (Exception ex){
            ex.printStackTrace();

        }finally {

        }
        return className;



    }
}